{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PHydro-cover-small.png\">\n",
    "*This is the Jupyter notebook version of the [Python in Hydrology](http://www.greenteapress.com/pythonhydro/pythonhydro.html) by Sat Kumar Tomer.*\n",
    "*Source code is available at [code.google.com](https://code.google.com/archive/p/python-in-hydrology/source).*\n",
    "\n",
    "*The book is available under the [GNU Free Documentation License](http://www.gnu.org/copyleft/fdl.html). If you have comments, corrections or suggestions, please send email to satkumartomer@gmail.com.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Linear Regression](05.07-Linear-Regression.ipynb) | [Contents](Index.ipynb) | [Interpolation](05.09-Interpolation.ipynb) >"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.8 多项式回归\n",
    "\n",
    "我们可以使用`np.polyfit`进行多项式回归。这提供了拟合系数。我们可以将多项式的阶次定义为`np.polyfit`函数的第三个参数。首先，我们生成一个二次多项式($y=1+2x-3x^2$),然后我们为它添加噪音。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-2.86740752  0.27702973  5.67132232]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "# 生成数据\n",
    "x = np.linspace(0,10)\n",
    "y = 1 + 2*x - 3*x**2 + 15*np.random.randn(50)\n",
    "# 拟合多项式\n",
    "z = np.polyfit(x,y,2)\n",
    "print(z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`np.polyfit`函数提供的拟合二项式为$y=4.58+1.34-3.03x^2$,然而真实的二项式系数是不一样的。只有第三个参数是合理计算的。其他两个参数与真实参数相差很远。让我们看看拟合二项式对比真实的二项式的表现方式。`np.polyld`函数用于使用由`np.polyfit`返回的拟合系数来评估多项式。图5.14显示了结果图。虽然拟合的系数不同于真实的系数，但拟合的多项式却接近于真实系数。与第二级相关的参数由`np.polyfit`合理计算，这意味着这是与其他参数相比最敏感的参数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAEKCAYAAADTgGjXAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3Xd4VGX2wPHvyaSS0ENvCU3pLQECqNEgZQVRAQULoAICsqLuKqKysLKKqz9XQcGGigVFRCkWpGnAhVAFlKZ0CDVACCGQ/v7+mCEbIAlJmJmbmZzP88xzZ+7ccibinHm7GGNQSimlisPH6gCUUkp5Lk0iSimlik2TiFJKqWLTJKKUUqrYNIkopZQqNk0iSimlik2TiFJKqWLTJKKUUqrYNIkopZQqNl+rA3C10NBQExYWZnUYSinlMTZu3HjSGFOlMMd6fRIJCwtjw4YNVoehlFIeQ0QOFPZYrc5SSilVbJpElFJKFZsmEaWUUsXm9W0iSqmSLSMjg/j4eFJTU60OpdQJDAykdu3a+Pn5FfsamkSUUpaKj4+nbNmyhIWFISJWh1NqGGM4deoU8fHxhIeHF/s6Wp2llLJUamoqlStX1gTiZiJC5cqVr7kEqEnEWeLiYPJk+1YpVSSaQKzhjL+7Vmc5Q1wcxMRAejr4+8Py5RAVZXVUSinlcloScYbYWHsCycqyb2NjrY5IKeVC//jHP1i2bJlTrxkSElLg+2fOnGH69OlOvaczaBJxhuhoewnEZrNvo6Otjkgp5UIvvPACXbt2des9NYl4s6goexXWpElalaWUOzixDXL//v00adKEYcOG0axZM7p168aFCxcA2Lx5Mx07dqRly5bceeedJCYmAjBkyBDmzp0LwDPPPE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at 0x2aabb339048>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "# evaluate polynomial\n",
    "p = np.poly1d(z)\n",
    "z_true = np.array([-3, 2, 1]) # coefficient of true polynomial\n",
    "p_true = np.poly1d(z_true) # true polynomial\n",
    "# plot\n",
    "plt.plot(x, y,'.r', label='noisy data')\n",
    "plt.plot(x, p_true(x), label='True curve')\n",
    "plt.plot(x, p(x), label='Fitted curve')\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('y')\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
